{include file="public/header" /}
<body class="gray-bg">
<div class="wrapper wrapper-content animated">
    <input type="hidden" id="group_id" name="group_id" value="{$Request.param.id}">
    <ul id="treeDemo" class="ztree"></ul>
    <input type="button" value="确认分配" class="btn btn-primary mt-5 ml-10" id="post_form"/>
</div>
{include file="public/footer" /}
<link rel="stylesheet" href="__LIB__/zTree/css/metroStyle/metroStyle.css" type="text/css">
<script type="text/javascript" src="__LIB__/zTree/js/jquery.ztree.core.js"></script>
<script type="text/javascript" src="__LIB__/zTree/js/jquery.ztree.excheck.js"></script>
<script>
    var setting = {
        check: {
            enable: true
        },
        data: {
            simpleData: {
                enable: true
            }
        },
        expandAll: true
    };

    var zNodes = {$treeRule};

    var code;

    function setCheck() {
        var zTree = $.fn.zTree.getZTreeObj("treeDemo");
        zTree.setting.check.chkboxType = {"Y": "ps", "N": "ps"};
    }

    $(document).ready(function () {
        var treeObj = $.fn.zTree.init($("#treeDemo"), setting, zNodes);
        treeObj.expandAll(true);
        setCheck();

        //确认分配权限
        $("#post_form").click(function () {
            var zTree = $.fn.zTree.getZTreeObj("treeDemo");
            var nodes = zTree.getCheckedNodes(true);
            var ruleString = '';
            $.each(nodes, function (n, value) {
                if (n > 0) {
                    ruleString += ',';
                }
                ruleString += value.id;
            });

            var id = $("#group_id").val();
            console.log(ruleString);
            $.post("{:\\think\\Url::build('auth')}", {'id': id, 'rule': ruleString}, function (res) {
                var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
                if (res.code == 1) {
                    layer.msg(res.msg, {icon: 1, time: 1500, shade: 0.1}, function () {
                        console.log(res);
                        parent.layer.close(index);
                    });
                } else {
                    layer.msg(res.msg);
                }
            }, 'json')
        })

    });
</script>
</body>
</html>
